package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.CureRecordDao;
import cn.topevery.garden.entity.po.CureRecord;
import cn.topevery.garden.entity.query.CureRecordQuery;
import cn.topevery.garden.entity.vo.CureRecordVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 防治记录
 *
 * @author code-generate
 * @date 2022-02-18
 */
@Repository
public class CureRecordDaoImpl extends BaseDaoImpl<CureRecord> implements CureRecordDao {
    @Override
    public <P extends DbCsp> List<CureRecord> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<CureRecordVO> listPage(CureRecordQuery query) {
        String table = "t_cure_record tcr";

        String columns = "tcr.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tcr.c_id desc");
        sqlQueryMate
                .where(true, "tcr.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getTreeCode()), "tcr.c_tree_code", ScriptConditionEnum.Eq, query.getTreeCode())
                .where(query.getConsultationStatus() != null, "tcr.c_consultation_status", ScriptConditionEnum.Eq, query.getConsultationStatus())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, CureRecordVO.class);
    }

    @Override
    public CureRecord getEntityByColumn(String key, String value) {
        KeyValue<String> map = new KeyValue<>();
        map.key = key;
        map.value = value;
        return getEntityByColumnEqValue(map);
    }
}
